package com.hsj.busmanager.service;

import com.hsj.busmanager.api.Butie;
import com.hsj.busmanager.api.Cost;
import com.hsj.busmanager.api.Rent;
import com.hsj.busmanager.api.ShowCost;
import com.hsj.busmanager.mapper.ButieMapper;
import com.hsj.busmanager.mapper.CostMapper;
import com.hsj.busmanager.mapper.RentMapper;
import com.hsj.busmanager.util.CommonUtil;
import com.hsj.busmanager.util.Page;
import com.hsj.busmanager.util.TabelData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class MountSerivce {

    @Autowired
    private RentMapper rentMapper;

    @Autowired
    private CostMapper costMapper;

    @Autowired
    private ButieMapper butieMapper;

    public TabelData<Rent> getrentCostData(Page page, Rent rent,Integer userId) {


        TabelData tabelData = new TabelData();

        Integer start = (page.getPage()-1)*page.getLimit();

        List<Rent> rentList = rentMapper.getrentCostPage(start,page.getLimit(),rent,userId);

        for(Rent rent1:rentList){
            rent1.setShowCreateTime(CommonUtil.getDateByFormat(rent1.getPayTime(),"yyyy-MM-dd"));
        }

        int count = rentMapper.getNormalProjectCount(rent,userId);

        if (rentList == null && rentList.size() == 0) {
            return null;
        }

        tabelData.setCount(count);
        tabelData.setData(rentList);

        return tabelData;

    }

    public TabelData<Cost> getOtherCostData(Page page, Cost cost,Integer userId) {

        TabelData tabelData = new TabelData();

        Integer start = (page.getPage()-1)*page.getLimit();

        List<Cost> costList = costMapper.getOtherCostPage(start,page.getLimit(),cost,userId);

        for(Cost cost1:costList){
            cost1.setShowCreateTime(CommonUtil.getDateByFormat(cost1.getCreateTime(),"yyyy-MM-dd"));
        }

        int count = costMapper.getOtherCostPageCount(cost,userId);

        if (costList == null && costList.size() == 0) {
            return null;
        }

        tabelData.setCount(count);
        tabelData.setData(costList);

        return tabelData;

    }

    public TabelData<Butie> getButieData(Page page, Butie butie) {

        TabelData tabelData = new TabelData();

        Integer start = (page.getPage()-1)*page.getLimit();

        List<Butie> butieList = butieMapper.getButiePage(start,page.getLimit(),butie);

        for(Butie butie2:butieList){
            butie2.setShowCreateTime(CommonUtil.getDateByFormat(butie2.getCreatTime(),"yyyy-MM-dd"));
        }

        int count = butieMapper.getButieCount(butie);

        if (butieList == null && butieList.size() == 0) {
            return null;
        }

        tabelData.setCount(count);
        tabelData.setData(butieList);

        return tabelData;


    }
}
